#ifndef DHD_S_CONNECTION_H
#define DHD_S_CONNECTION_H

#include "socket_io.h"
#include "s_srp_database.h"
#include "s_fuse_backend.h"

namespace dhd
{
   class ToServer;
   class ToClient;
   
namespace server
{
   class Server;

   class Connection : public Refcounted, public boost::noncopyable
   {
       tcp::endpoint     *endpoint;
       PSocketIO          sock_io;
       Server            &server;
       FuseBackend        fuse_backend;
       SRPVerifier       *srp_ver;
       bool               authenticated;
       
       void handle_message( uint16_t request_id, PBuffer header, PBuffer buffer );
       
       void on_read_error( const char * msg, bool reconnect = true );
       
       void on_zero_refcount() { delete this; }
       
     public:
       
       Connection( tcp::endpoint * _endpoint, 
                   tcp::socket   * _sock, 
                   ssl_socket    * _ssl_sock,
                   Server        & _server );
       
       ~Connection();
          
       void send_broadcast( PBuffer header, PBuffer buffer );
       
       const tcp::endpoint & get_endpoint() { return *endpoint; }
   };
   
   typedef boost::intrusive_ptr<Connection> PConnection;
      
   
} // end namespace dhd::server
} // end namespace dhd

   
#endif